/*******************************************************************
 *  Copyright(c) 2022-2032 zjg
 *  All rights reserved.
 *
 *  文件名称:CWebUserInfo.h
 *  简要描述:网页用户名密码
 *
 *
 *  创建日期:2022-04-16
 *  作者:江秀绳
 *  说明:
 *
 *  修改日期:
 *  作者:
 *  说明:
 ******************************************************************/

#ifndef QG_LOCAL_COMM_ENTRANCE_NETWORK_SERVICE_INCLUDE_CWEBUSERINFO_H_
#define QG_LOCAL_COMM_ENTRANCE_NETWORK_SERVICE_INCLUDE_CWEBUSERINFO_H_

#include "CNetworkServiceHeader.h"
#include "CcmdBase.h"
#include "CNetBase.h"

NETWORKSERVICE_BEGIN_NAMESPACE

// 网页端用户名密码
typedef struct _tUserInfo{
	XJSON_FUNCI
	// 用户名
	string username;
	// 密码
	string password;

	_tUserInfo()
	{
		clear();
	}
	_tUserInfo(string path)
	{
		clear();
		this->loadFlie(path);
	}

	bool operator!=(const _tUserInfo &p){
		return username != p.username
				|| password != p.password
				;
	}

	void clear()
	{
		username = "admin";
		password = "123456";
	}
	XPACK( O(username, password));

}T_UserInfo;

class NETWORKSERVICE_API CWebUserInfo:public CNetBase{

public:
	CWebUserInfo();
	// 10分钟超时
	void timerOut();
	static CWebUserInfo &getInstance(){
		return m_Instance;
	}
public:

	// 接收到设置网页端用户名密码  由 /login/setUser 命令触发
	bool rSetUser(struct tRouteData<T_UserInfo&> *recv,struct tRouteData<T_NullData> *send, void *userData);

	// 获取用户名密码
	static T_UserInfo& getUserInfo(){ return getInstance().__getUserInfo(); }

	// 获取用户名密码
	T_UserInfo& __getUserInfo(){ return m_localUserInfo; }


	// 恢复默认
	void resetDefault();

private:
	// 缓存用户名密码
	T_UserInfo m_localUserInfo;
	T_UserInfo m_NetUserInfo;

private:
	// 单例运行
	static CWebUserInfo m_Instance;

};

NETWORKSERVICE_END_NAMESPACE
#endif
